import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * This is the first screen of the GUI. It presents the user with
 * a choice of going into expert or wizard mode.
 * 
 * @author James Stanier
 */
public class GUI implements ActionListener {
	
	JButton expertButton;
	JButton wizardButton;
	JFrame window;
	
	/**
	 * Main method for standalone running.
	 * @param args Input fields.
	 */
	public static void main(String[] args) {
		GUI gui = new GUI();
		gui.welcomeScreen();
	}
	
	/**
	 * Configures and draws the screen.
	 */
	public void welcomeScreen() {
		window = new JFrame("JavaLiN - Welcome");
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.setSize(450,350);
		window.setLocationRelativeTo(null);
        window.toFront();
		window.setResizable(false);
		
		// Introductory passage and logo
		JPanel top = new JPanel();
		top.setLayout(new BorderLayout());
		top.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		
		// Logo
		JLabel logo = new JLabel();
		logo.setIcon(new ImageIcon("logo.png"));
		logo.setHorizontalAlignment(JLabel.CENTER);
		top.add(logo, BorderLayout.NORTH);
		// Intro text
		JLabel intro = new JLabel("<HTML>Before starting, please choose the mode you wish to " +
				"operate in:</HTML>");
		intro.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
		intro.setHorizontalAlignment(JLabel.CENTER);
		top.add(intro, BorderLayout.SOUTH);
		
		// Buttons and labels
		JPanel bottom = new JPanel();
		bottom.setLayout(new GridLayout(2,2));
		bottom.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		
		JLabel wizard = new JLabel("<HTML>If you have not used this program before, the wizard mode will guide you " +
				"through creation of your report.</HTML>");
		wizard.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
		bottom.add(wizard);
		wizardButton = new JButton("Wizard mode");
		wizardButton.setPreferredSize(new Dimension(25, 25));
		wizardButton.addActionListener(this);
		bottom.add(wizardButton);
		
		JLabel expert = new JLabel("<HTML>If you have used this program before and are confident, use expert mode.</HTML>");
		expert.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
		bottom.add(expert);
		expertButton = new JButton("Expert mode");
		expertButton.addActionListener(this);
		bottom.add(expertButton);
		
		// Add panels to main window
		window.add("North", top);
		window.add("South", bottom);
		window.validate();
		window.setVisible(true);
	
	}
	
	/**
	 * Actions to be taken upon component interaction.
	 */
	public void actionPerformed(ActionEvent e) { 
		if(e.getSource().equals(expertButton)) {
			window.setVisible(false);
			FileIOGUI fgui = new FileIOGUI(window, "expert");
		}
		else if(e.getSource().equals(wizardButton)) {
			window.setVisible(false);
			FileIOGUI fgui = new FileIOGUI(window, "wizard");
		}
    }
}
